﻿
<?php
//清除缓存
ob_clean();

    if(!empty($_POST)){

           $name = $_POST['name'];

           $pid = $_POST['pid'];


        // print_r($_POST);

        $sql = "INSERT INTO `cate`(`name`,`pid`) VALUES ('$name','$pid')";

           mysqli_query($link,'set names utf8');

        mysqli_query($link,$sql);

       $xf=mysqli_affected_rows($link);


        // print_r($xf);
               //判断$xf的值是否大于0，大于则编辑成功
           if($xf>0){

               echo '<script>alert("编辑成功");location.href="index.php?c=cate&&a=list&&admin=1"; </script>';

            }else{

        echo '<script>alert("编辑失败");history.go(-1) </script>';
      }
}

      $id = empty($_GET['id'])?0:$_GET['id'];

      //查询顶级分类
      $sql = "select * from `cate` where pid=$id";
      $result =  mysqli_query($link,$sql);
      while ($arr = mysqli_fetch_assoc($result)) {
         $cate[] = $arr;
      }
  // print_r($cate);
  // echo($cate);
       if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){

                echo json_encode($cate);die;
       }

 //载入后台公共视图
    include_once (VIEW_PATH.'admin/layout.html');
?>